# -*- coding: utf-8 -*-
'''
国家药品监督管理局--化妆品公司生产许可证信息
'''
import json
import requests

id_list = []
url_main = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList'
proxies = {"http": None, "https": None}
params = {
    'on': 'true',
    'page': '1',            # 如果获取多页变更page参数，这个是页码
    'pageSize': '15',       # 每页只能固定获取15条，变更这个没有效果
    'productName': '',
    'conditionType': '1',
    'applyname': '',
    'applysn': ''
}
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'
}
response = requests.post(url=url_main, proxies=proxies, headers=headers, params=params).text
# 将response转化为字典类型
response_dic = json.loads(response)

for id in response_dic['list']:
    id_list.append(id['ID'])
# print(id_list)

url_son = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
for i in id_list:
    params = {'id' : i}
    details = requests.post(url=url_son, proxies=proxies, headers=headers, params=params).text
    # 将str格式化为字典形式，再根据key获取对应的值，就不一个个去找了，直接全部结果打印出来了
    details_dic = json.loads(details)
    print(details_dic)
    # print(details_dic['epsName'])